package com.ad2campaign.engine.db.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;

import com.ad2campaign.engine.db.model.Node;
import com.ad2campaign.engine.db.rowmapper.NodeMapper;

public class NodeDaoImpl implements NodeDao  
{
	private JdbcTemplate jdbcTemplate;
	private NodeMapper nodeMapper;
	protected static final Logger LOGGER = Logger.getLogger(NodeDaoImpl.class);
	public NodeMapper getNodeMapper() {
		return nodeMapper;
	}

	public void setNodeMapper(NodeMapper nodeMapper) {
		this.nodeMapper = nodeMapper;
	}

	private String getNodesQuery;
	
	
	public String getGetNodesQuery() {
		return getNodesQuery;
	}

	public void setGetNodesQuery(String getNodesQuery) {
		this.getNodesQuery = getNodesQuery;
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	@Override
	public List<Node> getNodes() 
	{
		String sql = getNodesQuery;
		try 
		{
			return jdbcTemplate.query(sql, nodeMapper);
		} catch (Exception e) 
		{
			LOGGER.error("getNodes() : "+e.getMessage());
			LOGGER.debug(e);
			return new ArrayList<Node>(0);
		}
	}

}
